<html>
    <head>
        <title>覆盖领域服务</title>
    </head>
    <body>
        <script>
             /*

                    三、覆盖领域服务
                                    eg: 覆盖领域服务

                                                [Dependency(ReplaceServices = true)]
                                                [ExposeServices(typeof(IdentityUserManager))]  // 暴露的服务类型
                                                public class MyIdentityUserManager : IdentityUserManager
                                                {
                                                        public MyIdentityUserManager(
                                                            IdentityUserStore store,
                                                            IIdentityRoleRepository roleRepository,
                                                            IIdentityUserRepository userRepository,
                                                            IOptions<IdentityOptions> optionsAccessor,
                                                            IPasswordHasher<IdentityUser> passwordHasher,
                                                            IEnumerable<IUserValidator<IdentityUser>> userValidators,
                                                            IEnumerable<IPasswordValidator<IdentityUser>> passwordValidators,
                                                            ILookupNormalizer keyNormalizer,
                                                            IdentityErrorDescriber errors,
                                                            IServiceProvider services,
                                                            ILogger<IdentityUserManager> logger,
                                                            ICancellationTokenProvider cancellationTokenProvider) :
                                                            base(store,
                                                                roleRepository,
                                                                userRepository,
                                                                optionsAccessor,
                                                                passwordHasher,
                                                                userValidators,
                                                                passwordValidators,
                                                                keyNormalizer,
                                                                errors,
                                                                services,
                                                                logger,
                                                                cancellationTokenProvider)
                                                        {
                                                        }

                                                    public async override Task<IdentityResult> CreateAsync(IdentityUser user)
                                                    {
                                                        if (user.PhoneNumber.IsNullOrWhiteSpace())
                                                        {
                                                            throw new AbpValidationException(
                                                                "Phone number is required for new users!",
                                                                new List<ValidationResult>
                                                                {
                                                                    new ValidationResult(
                                                                        "Phone number can not be empty!",
                                                                        new []{"PhoneNumber"}
                                                                    )
                                                                }
                                                            );
                                                        }

                                                        return await base.CreateAsync(user);
                                                    }
                                                }

                                        此示例类继承自IdentityUserManager域服务并覆盖CreateAsync方法以执行上面实现的相同电话号码检查。

                                        结果是相同的，但这次我们在域服务中实现了它，假设这是我们系统的核心域逻辑。

                                                
                                        注意：
                                                [ExposeServices(typeof(IdentityUserManager))]属性是必需的因为IdentityUserManager没有定义接口（如IIdentityUserManager）
                                                
                                                并且依赖注入系统不会按照约定为继承的类公开服务（如为实现的接口）。

                */
        </script>
    </body>
</html>